<?php
namespace jy_creditshop;
defined('BY_JYA') or exit('error');
/*
	消息提醒
*/
class notice extends \plugin{
	public function notice_create2buyer($order,$url=''){
		//发送订单生成通知给买方		
		$template_id=cfc('account')->get_tpl_template_id('42830','订单提交成功通知','',array('消费门店','消费时间','消费项目','消费金额'));
		if($_SESSION['wxapp_id']){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('3534',[1,2,3,4],'create2buyer','订单提交成功通知','jy_creditshop');
		}
		$basic=$this->plugin_setting('basic');
		$message=array(
			array('value'=>$basic['title']?:'积分商城',"name" =>"thing36",'title'=>'消费门店'),
			array('value'=>date('Y-m-d H:i:s',$order['createtime']),"name" =>"time6",'title'=>'消费时间'),
			array('value'=>$order['goods']['title']?:'积分商品',"name" =>"thing2",'title'=>'消费项目'),
			array('value'=>price($order['money']),"name" =>"amount3",'title'=>'消费金额'),
		);
		$statustitle=$order['status']==1?'已下单':'待支付';
		$wxappmsg=array(
			array('value'=>$order['logno']),
			array('value'=>$this->order_status[$order['status']]),
			array('value'=>$order['goods']['title']),
			array('value'=>price($order['money'])),
		);
		if(!$url){
			$url=custom_url('jy_creditshop/log_detail//id='.$order['id'],true);	
		}
		if(method_exists(cfc('account'),'sendtwoNotice')){
			cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'create2buyer','jy_creditshop',$order['id']);
		}
		if($_SESSION['wxapp_id']){
			cfc('wxapp_api')->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'create2buyer','jy_creditshop',$order['id']);
		}
		return '';
	}
	public function notice_cancel2buyer($order){
		//发送订单取消通知给买方		
		$template_id=cfc('account')->get_tpl_template_id('50766','订单取消通知','',array('订单金额','商品名称','配送地址','订单号'));
		$address_str=model('core/member')->get_address_str($order['addressid']);
		$message=array(
			array('value'=>$order['money'],"name" =>"amount3"),
			array('value'=>$order['goods']['title']?:'积分商品',"name" =>"thing2"),
			array('value'=>$address_str,"name" =>"thing4"),
			array('value'=>$order['logno'],"name" =>"character_string1"),
		);
		$url=custom_url('jy_creditshop/log_detail//id='.$order['id'],true);
		if(method_exists(cfc('account'),'sendtwoNotice')){
			cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'cancel2buyer','jy_creditshop',$order['id']);
		}
		
	}
	public function notice_pay2buyer($order,$url=''){
		//发送订单支付通知给买方
		$basic=$this->plugin_setting('basic');
		$template_id=cfc('account')->get_tpl_template_id('43216','订单支付成功通知','',array('订单号','支付金额','支付方式','商品名称','门店'));
		if($_SESSION['wxapp_id']){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('30808',[1,13,7,5,8],'pay2buyer','订单支付成功通知','jy_creditshop');
		}
		$is_pays =array('0'=>'未支付','1'=>'已支付');
		$paytitle=($order['status']==1 && $order['paystatus']!=1)?'货到付款':'线上支付';
		$statustitle=$is_pays[$order['paystatus']].'-('.$paytitle.')';
		$message=array(
			array('value'=>$order['logno'],"name" =>"character_string2"),
			array('value'=>$order['money'],"name" =>"amount5"),
			array('value'=>$statustitle,'name'=>'thing6'),
			array('value'=>$order['goods']['title']?:'积分商品',"name" =>"thing3"),
			array('value'=>$basic['title']?:'积分商城',"name" =>"thing8"),
		);
		$wxappmsg=array(
			array('value'=>$order['logno'],"name" =>"character_string2"),
			array('value'=>$order['money'],"name" =>"amount5"),
			array('value'=>$is_pays[$order['ispay']],'name'=>'thing6'),
			array('value'=>$order['goods']['title']?:'积分商品',"name" =>"thing3"),
			array('value'=>$basic['title']?:'积分商城',"name"=>"thing8"),
		);
		if(!$url){
			$url=custom_url('jy_creditshop/log_detail//id='.$order['id'],true);
		}
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'pay2buyer','jy_creditshop',$order['id']);
		if($_SESSION['wxapp_id']){
			$template_id=cfc('wxapp_api')->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'pay2buyer','jy_creditshop',$order['id']);
		}
	}
	public function notice_pay2seller($order,$seller_id=0){
		//发送订单生成通知给卖方
		$template_id=cfc('account')->get_tpl_template_id('43216','订单支付成功通知','',array('订单号','支付金额','支付方式','商品名称'));
		$is_pays =array('0'=>'未支付','1'=>'已支付');
		$paytitle=($order['status']==1 && $order['paystatus']!=1)?'货到付款':'线上支付';
		$statustitle=$is_pays[$order['paystatus']].'-('.$paytitle.')';
		$message=array(
			array('value'=>$order['logno'],"name" =>"character_string2"),
			array('value'=>$order['money'],"name" =>"amount5"),
			array('value'=>$statustitle,'name'=>'thing6'),
			array('value'=>$basic['title']?:'积分商城',"name" =>"thing8"),
			array('value'=>$order['goods']['title']?:'积分商品',"name" =>"thing3"),
		);
		if(method_exists(cfc('account'),'sendtwoNotice')){
			cfc('account')->sendtwoNotice($seller_id,$template_id,$message,'','create2seller','jy_creditshop',$order['id']);
		}
	}
	public function notice_send2buyer($order,$url=''){
		//发送订单发货通知给买方
		$template_id=cfc('account')->get_tpl_template_id('42984','订单发货通知','',array('商品名称','订单编号','快递公司','快递单号','收货地址'));
		if($_SESSION['wxapp_id']){
			$wxapptemplate_id=cfc('wxapp_api',$wxapp_id)->get_tpl_template_id('30766',[1,2,4,5,9],'send2buyer','订单发货通知','jy_creditshop');
		}	
		$address_str=model('core/member')->get_address_str($order['addressid']);
		$express_types=model('jy_weishop/model')->express_types();
		$message=array(
			array('value'=>$order['goods']['title']?:'积分商品',"name" => "thing4"),
			array('value'=>$order['logno'],"name" => "character_string2"),
			array('value'=>$express_types[$order['express']]['name']?:'无',"name" => "thing13"),
			array('value'=>$order['expresssn'],"name" => "character_string14"),
			array('value'=>$address_str,"name" => "thing19"),
			array('value'=>date('Y-m-d H:i:s',$order['createtime']),"name" => "time17"),
			array('value'=>date('Y-m-d H:i:s',$order['time_finish']),"name" => "time12"),
		);
		$wxappmsg=array(
			array('value'=>$order['goods']['title']?:'积分商品'),
			array('value'=>$order['logno']),
			array('value'=>$express_types[$order['express']]['name']?:'无'),
			array('value'=>$order['expresssn']),
			array('value'=>$address_str),
		);
		if(!$url){
			$url=custom_url('jy_creditshop/log_detail//id='.$order['id'],true);
		}
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'send2buyer','jy_creditshop',$order['id']);
		if($_SESSION['wxapp_id']){
			$template_id=cfc('wxapp_api')->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'send2buyer','jy_creditshop',$order['id']);
		}
	}
	public function notice_receive2buyer($order){
		//发送订单收货通知给买方
		$template_id=cfc('account')->get_tpl_template_id('42984','订单确认收货通知','',array('订单编号','商品名称','购买时间','发货时间'));
		$address_str=model('core/member')->get_address_str($order['addressid']);
		$express_types=model('jy_weishop/model')->express_types();
		$message=array(
			array('value'=>$order['logno'],"name" => "character_string2"),
			array('value'=>$order['goods']['title'],"name" => "thing4"),
			array('value'=>$express_types[$order['express']]['name']?:'无',"name" => "thing13"),
			array('value'=>date('Y-m-d H:i:s',$order['createtime']),"name" => "time17"),
			array('value'=>date('Y-m-d H:i:s',$order['time_finish']),"name" => "time12"),
			array('value'=>$order['expresssn'],"name" => "character_string14"),
			array('value'=>$address_str,"name" => "thing19"),
		);
		$url=custom_url('jy_creditshop/log_detail//id='.$order['id'],true);
		cfc('account')->sendtwoNotice($order['mid'],$template_id,$message,$url,'receive2buyer','jy_creditshop',$order['id']);
	}
}
